I have the following form
using (Ajax.BeginRouteForm(
...
new AjaxOptions
{
HttpMethod = "POST",
OnFailure = "OnFailure",
OnSuccess = "OnSuccess"
}))
{
..,.
}
I implement the OnSuccess function in a TypeScript file. I am trying to make this function more TypeScripty. At the moment I have this
function OnSuccess(data: what type goes here?) {
...
// use data.SomeValue here
...
}
Question is what type shall I say data is such that I can still somehow use data.SomeValue?
Pravesh Singh
23-Jan-2014The best way is with an interface, because you make an explicit assertion of the structure of the object returned and communicate very clearly what the callback expects.
export interface IOnSuccessArgs {propertyA: string;
propertyB: number;
}
function OnSuccess(data: IOnSuccessArgs): void {
// ... data has propertyA and propertyB
}